package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-19
 * Time: 21:37
 */

//https://www.nowcoder.com/practice/1a3de8b83d12437aa05694b90e02f47a?tpId=46&&tqId=29171&rp=1&ru=/ta/classic-code&qru=/ta/classic-code/question-ranking
public class Solution9 {
    /**
     * @param x int整型
     * @return int整型
     */
    public int reverse(int x) {
        long reverse = 0;
        while (x != 0) {
            reverse = reverse * 10 + x % 10;
            x /= 10;
        }
        if (reverse >= Integer.MIN_VALUE && reverse <= Integer.MAX_VALUE) {
            return (int) reverse;
        }
        return 0;

        //或者这样返回
        //return reverse == (int) reverse ? (int) reverse : 0;
    }
}
